#include "bsp_signal_led.h"

/****************************
信号强度指示灯
****************************/
void SIGNAL_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
	
  RCC_APB2PeriphClockCmd(SIGNAL_LED_RCC, ENABLE);	    
	GPIO_InitStructure.GPIO_Pin = SIGNAL_LED1_PIN |SIGNAL_LED2_PIN |SIGNAL_LED3_PIN |SIGNAL_LED4_PIN;              
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;           
  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  GPIO_Init(SIGNAL_LED_PORT, &GPIO_InitStructure);
	
	
}



/****************************
设置信号强度0~100
****************************/
void SIGNAL_SetStrength(uint8_t s)
{
	if(s==0)
	{
		SIGNAL_LED4_OFF;
		SIGNAL_LED2_OFF;
		SIGNAL_LED3_OFF;
		SIGNAL_LED4_OFF;
	}
	else if(s<=25)
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_OFF;
		SIGNAL_LED3_OFF;
		SIGNAL_LED4_OFF;
	}
	else if(s<=25)
	{
		SIGNAL_LED1_ON;

	}
	else	if(s<=50)
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_ON;
		SIGNAL_LED3_OFF;
		SIGNAL_LED4_OFF;
	}
	else if(s<=75)
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_ON;
		SIGNAL_LED3_ON;
		SIGNAL_LED4_OFF;
	}
	else
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_ON;
		SIGNAL_LED3_ON;
		SIGNAL_LED4_ON;
	}
}



/****************************
更新状态显示    
调用频率50ms一次
****************************/
void SIGNAL_UpdataMode(void)
{
	static uint8_t count=0;
	count+=2;
	if(count>=100)   count=0;
	if(count==0)
	{
		SIGNAL_LED4_OFF;
		SIGNAL_LED2_OFF;
		SIGNAL_LED3_OFF;
		SIGNAL_LED4_OFF;
	}
	else if(count<=25)
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_OFF;
		SIGNAL_LED3_OFF;
		SIGNAL_LED4_OFF;
	}
	else	if(count<=50)
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_ON;
		SIGNAL_LED3_OFF;
		SIGNAL_LED4_OFF;
	}
	else if(count<=75)
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_ON;
		SIGNAL_LED3_ON;
		SIGNAL_LED4_OFF;
	}
	else
	{
		SIGNAL_LED1_ON;
		SIGNAL_LED2_ON;
		SIGNAL_LED3_ON;
		SIGNAL_LED4_ON;
	}
}